<!DOCTYPE html>
<meta charset="utf-8" />

<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form action="mpamng/agent/queryAgent.do" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">合作商编号:</label>
							<div class="search_input">
								<input id="search_agentId" type="text" name="agentId" placeholder="请输入合作商编号"/>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">登录账户:</label>
							<div class="search_input">
								<input id="search_logonName" type="text" name="logonName" placeholder="请输入合作商登陆账户"/>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">合作商名称:</label>
							<div class="search_input">
								<input id="search_agentName" type="text" name="agentName" placeholder="合作商名称"/>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">法人姓名:</label>
							<div class="search_input">
								<input id="search_legalName" type="text" name="legalName" placeholder="请输入法人姓名"/>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">OEM:</label>
							<div class="search_input">
								<select 
									 rel="obj.OEM_STATE"
						 			 location="local" 
									 name="oemState" 
						 			id="search_oemState" 
						 			data-placeholder="请选择状态" style="width: 130px;vertical-align:middle;">
									<option value='' >----请选择----</option>
								</select>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">合作商状态:</label>
							<div class="search_input">
								<select 
									 rel="obj.AGENTSTATUS"
						 			 location="local" 
									 name="agentStatus" 
						 			id="search_agentStatus" 
						 			data-placeholder="请选择状态" style="width: 130px;vertical-align:middle;">
									<option value='' >----请选择----</option>
								</select>
							</div>
						</div>
						<div class="search_elm">
							<button class="btn btn-small btn_search" type="submit" title="搜索" > 搜索 </button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>
	<div class="rowt">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			<div style="margin-top: 10px">
				<span id="termCom_btn">
<!-- 					<a auth="agent/agentPasswdReset.do" class="btn btn-small btn-delete" onclick="resetAgentPwd();"> <i class="icon-envelope"></i> 重置密码</a> -->
				</span> <span id="paging_bar" style="float: right"> </span>
			</div>

			<!-- PAGE CONTENT ENDS -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<!-- page specific plugin scripts -->
	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',
								$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'
								|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',
										parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({
				url : "mpamng/agent/queryAgent.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : [ '合作商编号', '合作商登录账号', '合作商名称','法人姓名','父合作商编号','一级合作商编号','保证金','OEM','合作商状态','开户时间','操作' ],
				colModel : [ {name : 'agentId',           index : 'agentId',          width : '100px'},
				             {name : 'logonName',         index : 'logonName',        width : '120px'},
				             {name : 'agentName',         index : 'agentName',        width : '130px'},
				             {name : 'legalName',         index : 'legalName',        width : '120px'}, 
				             {name : 'fathAgentId',		  index : 'fathAgentId',      width : '120px'}, 
				             {name : 'firstAgentId',      index : 'firstAgentId',     width : '120px'}, 
				             {name : 'margin',            index : 'margin',           width : '100px'}, 
				             {name : 'oemState',          index : 'oemState',         width : '60px', ditcKey:'OEM_STATE', formatter : gridFormatByDict}, 
				             {name : 'agentStatus',       index : 'agentStatus',      width : '80px', ditcKey:'AGENTSTATUS', formatter : gridFormatByDict}, 
				             {name : 'createDate',        index : 'createDate',       width : '150px',formatter : gridFormatByDate}, 
				             {name : 'aaa',                  index : 'aa',                 width : '100px',        formatter:optionEdit}
				            ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,
				shrinkToFit:false,
				multiselect : true,//设置行可多选的 
				multiboxonly : true,//
				sortable:false,

				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});
			
			//定义按钮
			function optionEdit(cellvalue, options, rowObject) {
				var button = "<div class=\"hidden-sm hidden-xs btn-group\">";  //定义button
				button += "<button class='btn btn-xs btn-warning'  title='路由配置' onclick='javascript:editeAgentOrgView(\""+rowObject["agentId"]+"\",\""+rowObject["agentName"]+"\");'>路由配置</button>";
				button += "</div>"; 
				return button;
			}
		});

		//详情
		function selectAgent(agentId) {
			if(agentId.length<=0){
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			var scrWidth = document.body.scrollWidth;
			openDialog({
				dialogId : 'dlg-agentEdit',
				title : '合作商详情',
				pageUrl : 'mpamng/agent/agentView.do',
				dataUrl : 'mpamng/agent/queryAgentById.do',
				width : scrWidth*0.8 , //
				height : '100%' , //
				dataParam : {
					agentId : agentId,
					type:'view'
				},
				dataName : 'obj,map'//表单数据存储对象名称

			});
		}
		
		//修改
		function updateAgent(agentId) {
			if(agentId.length<=0){
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			var scrWidth = document.body.scrollWidth;
			openDialog({
				dialogId : 'dlg-agentEdit',
				title : '合作商详情',
				pageUrl : 'mpamng/agent/agentView.do',
				dataUrl : 'mpamng/agent/queryAgentById.do',
				width : '80%',
				height : '100%' , //
				dataParam : {
					agentId : agentId,
					type:'edit'
				},
				dataName : 'obj,map' //表单数据存储对象名称

			});
		}
		//重置密码
		function resetAgentPwd() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "warn");
				return;
			}

			//
			var ids = "";
			for (var i = 0; i < rows.length; i++) {
				　ids += $('#grid-table').jqGrid('getRowData',rows[i]).agentId+ ",";
			}
			ids = ids.substring(0, ids.lastIndexOf(","));
			msg.confirm({title:'确认',position:'center',msg:'您确定要重置选中的合作商密码吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
						url : "mpamng/agent/agentPasswdReset.do?agentIds=" + ids,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});

				}
			}});
			
			}
		
		function editeAgentOrgView(agentId,agentName) {
			if(agentId.length<=0){
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			var scrWidth = document.body.scrollWidth;
			openDialog({
				dialogId : 'dlg-editeAgentOrg',
				title : '['+agentName+']  大商户配置',
				pageUrl : 'mpamng/agent/editeAgentOrgView.do',
				dataUrl : 'mpamng/agent/queryAgentOrgById.do',
				width : '90%',
				height:'95%',
				dataParam : {
					agentId : agentId
				},
				dataName : 'obj,map' //表单数据存储对象名称

			});
		}
	</script>